﻿using System;
using System.Collections.Generic;

using UnityEngine;
using UnityEngine.UI;


public class Tips : MonoBehaviour
{

    private static Tips instance = null;
    public static Tips GetInstance()
    {
        return instance;
    }

    void Awake()
    {
        instance = this;

        gameObject.SetActive(true);

        bottomObject.SetActive(false);
        topObject.SetActive(false);
    }


    public Text bottomTip = null;
    public Text topTip = null;

    public GameObject bottomObject
    {
        get
        {
            if (bottomTip != null)
                return bottomTip.gameObject.transform.parent.gameObject;
            else
                return null;
        }
    }

    public GameObject topObject
    {
        get
        {
            if (topTip != null)
                return topTip.gameObject.transform.parent.gameObject;
            else
                return null;
        }
    }



    // 展示底部标签提示
    public static void ShowBottomTip( string info, float time = 0 )
    {
        instance.bottomObject.SetActive(true);
        instance.bottomTip.text = info;
        instance.bottomTip.color = new Color(0.01f,0.21f,0.21f, 1f); //Color.black;

        instance.CancelInvoke("HideBottomTip");
        if ( time > 0 )
        {
            instance.Invoke("HideBottomTip", time);
        }
    }

    public static void ShowBottomTip( string info , Color color, float time = 0)
    {
        ShowBottomTip(info, time);
        instance.bottomTip.color = color;
    }


    public static void CloseBottomTip()
    {
        instance.HideBottomTip();
    }

    protected void HideBottomTip()
    {
        GetInstance().bottomObject.SetActive(false);
    }



    public static bool IsTop( string info )
    {
        if (info == null)
            return false;

        if (info.Equals(instance.topTip.text))
            return true;
        else
            return false;
    }

    public static bool IsBottom(string info)
    {
        if (info == null)
            return false;

        if (info.Equals(instance.bottomTip.text))
            return true;
        else
            return false;
    }

    // 展示顶部标签提示
    public static void ShowTopTip(string info, float time = 0)
    {
        if (instance == null)
            return;

        instance.topObject.SetActive(true);
        instance.topTip.text = info;

        if (time > 0)
        {
            instance.CancelInvoke("HideTopTip");
            instance.Invoke("HideTopTip", time);
        }
    }

    public static void CloseTopTip()
    {
        instance.HideTopTip();
    }

    protected void HideTopTip()
    {
        GetInstance().topObject.SetActive(false);
    }


    public static void Alpha( float to, float time )
    {
        LeanTween.alpha(instance.gameObject.GetComponent<RectTransform>(), to, time);
    }

    public static void AlphaBack( float time )
    {
        LeanTween.alpha(instance.gameObject.GetComponent<RectTransform>(), 1f, time);
    }

}

